/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * <p>Project: jse2302 - MapTest
 * <p>Powered by webrx On 2023-06-25 17:32:16
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class MapTest {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("java", 28);
        map.put("javascript", 15);

        System.out.println(map.size());

        //遍历keys
        Set<String> ks = map.keySet();
        for (String k : ks) {
            System.out.printf("map.get(\"%s\")=%d%n", k, map.get(k));
        }

        System.out.println("-------------------------");
        Iterator<Map.Entry<String, Integer>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("-------------------------");


        //遍历values
        Collection<Integer> vs = map.values();
        for (Integer i : vs) {
            System.out.println(i);
        }

        //遍历Map.Entry
        //Set<Map.Entry<String, Integer>> es = map.entrySet();
        var es = map.entrySet();
        for (Map.Entry<String, Integer> entry : es) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
            System.out.println(entry);
        }

        //java 迭代器工具类(主要功能是用来遍历集合)


    }
}
